@extends('admin.common.base-master')

@section('html-head')
    {{--<link href="{{url('/vendor/tyupload/control/css/zyUpload.css')}}" type="text/css" rel="stylesheet" />--}}
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    {{--<script src="{{url('/vendor/My97DatePicker/WdatePicker.js')}}"></script>--}}
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>

    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">分销规则设置</a>
        </div>
        <!-- cur-position end -->
        @include('admin.common.distribution-header')
        <div class="gg-step">
            <form  id="advform">
                <div class="gg-list">
                    <label class="tit">最大分销层级</label>
                    <div class="cont">
                        <p class="text">1-3级</p>
                        <select name="highest_level" id="highest_level">
                            <option value="0" @if($distribution && $distribution->highest_level == 0)selected @endif>禁用</option>
                            <option value="1" @if($distribution && $distribution->highest_level == 1)selected @endif>一级</option>
                            <option value="2" @if($distribution && $distribution->highest_level == 2)selected @endif>二级</option>
                            <option value="3" @if($distribution && $distribution->highest_level == 3)selected @endif>三级</option>
                        </select>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">一级佣金比率</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入返成百分比" name="first_ratio" id="first_ratio" value="@if($distribution){{$distribution->first_ratio}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">如8.23%，请输入8.23，系统只保留2位小数</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">二级佣金比率</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入返成百分比" name="secondary_ratio" id="secondary_ratio" value="@if($distribution){{$distribution->secondary_ratio}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">如2.34%，请输入2.34</p>
                    </div>
                </div>

                <div class="gg-list">
                    <label class="tit">三级佣金比率</label>
                    <div class="cont">
                        <input class="gg-ipt" type="text" placeholder="请输入返成百分比" name="three_ratio" id="three_ratio" value="@if($distribution){{$distribution->three_ratio}}@endif" /><cite id="title_re" class="required">*</cite>
                        <p class="text">如1.23%，请输入1.23</p>
                    </div>
                </div>

                
                <div class="gg-list">
                    <label class="tit">最低提现金额</label>
                    <div class="cont">
                        <input type="text" class="gg-ipt" placeholder="请输入金额" name="minimal_withdraw_limit" id="minimal_withdraw_limit" value="@if($distribution){{$distribution->minimal_withdraw_limit}}@endif"><cite id="title_re" class="required">*</cite>
                        <p class="text">如最低提现金额为1块钱，请输入1，不做限制请输入0</p>
                    </div>
                </div>


            </form>
            <div class="gg-list" >
                <label class="tit">&nbsp;</label>
                <div class="cont" >
                    <a href="javascript:;" class="next-step" id="btn-set">提交</a>
                </div>
            </div>
        </div>
    </div>

    <!-- content end -->
    <script>
        $(function() {

            $(document).on('click', '#btn-set', function () {
                var highest_level           = $('#highest_level option:selected').val();
                var first_ratio             = $('#first_ratio').val();
                var secondary_ratio         = $('#secondary_ratio').val();
                var three_ratio             = $('#three_ratio').val();
                var minimal_withdraw_limit  = $('#minimal_withdraw_limit').val();


                $.ajax({
                    url: '{{route("Distribution.Admin.setDistributionRule")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        highest_level:highest_level,
                        first_ratio:first_ratio,
                        secondary_ratio:secondary_ratio,
                        three_ratio:three_ratio,
                        minimal_withdraw_limit:minimal_withdraw_limit,
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.href = "{{route('Distribution.Admin.setDistributionRulePage')}}";
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: onbj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });
        });
    </script>
@endsection